/** The following class aims to create dron's mind,
 * 	as the dron progresses, its mind will be built.
 *
 * @author Sergio Damián
 * @version 1.0 Nov 10, 2013.
 */

package proyecto;

import java.util.ArrayList;

import proyecto.Drone.move;

/**
 * @author Sergio Damián Delgado González
 *
 */
public class Mind {
	

	/** Enum for the different states */
	enum state {UNKNOWN,	/** Position unknown yet */
				OBSTACLE,	/** There's an obstacle */
				CROSSED,	/** There isn't an obstacle, you've already crossed it */
				UNCROSSED,	/** There isn't an obstacle, you haven't crossed it yet */
				TARGET,		/** The target!		*/
				OUTOFRANGE};/** Position out of range of dron's mind */
		    			
	/** Matrix */
	private ArrayList<ArrayList<state> > mind;
	/** Matrix size */
	private int fil, col;
	/** Drons pos */
    private int posX;
    private int posY;
    
    /** areThereObstacles **/
    boolean obstacles;
    
    /** limitedMovementsIfThereAreObstacles **/
    private ArrayList<move> limitedMoves;

    /** tamCircles **/
    int tam=0;
    
    /** batteryCHarge **/
    int batteryCharge;
    
	/** Default constructor
	 */
	public Mind(int initialBatteryCharge){
		batteryCharge = initialBatteryCharge;
		fil=col=0;
		obstacles=false;
		mind = new ArrayList<ArrayList<state> >();
		limitedMoves = new ArrayList<move>();
	}
	
	/** Constructor with two parameters
	 * 	Initilize matrix with UNKNOWN and 0,0 position with CROSSED
	 * 
	 * @param f			Number of rows
	 * @param c			Number of columns
	 */
	public void createMind (int f, int c){
		fil=f;
		col=c;

		if (fil>0 && col>0){
			for (int i=0; i<fil ; i++){
				mind.add(new ArrayList<state>());
				for (int j=0; j<col ; j++){
					mind.get(i).add(state.UNKNOWN);
				}
			}
			mind.get(0).set(0,state.CROSSED);
		}
	}
	

	/** Function to insert a single element
	 * 
	 * @param f			Number of rows where we want to set the value
	 * @param c			Number of columns where we want to set the value
	 * @param value		State value
	 * @return boolean	Return if there was an error
	 */
	public boolean set(int f, int c, state value){
		
		//System.out.println("filas = "+f+" y columnas = "+ c);
		if (f<fil && c<col && f>=0 && c>=0){
			//System.out.println("Ponemos en la pos["+f+"]["+c+"] el valor "+value);
			if ( getState(f,c) != state.CROSSED )
				mind.get(f).set( c , value);
			return true;
		}
		else{
			return false;
		}
	}
	
	/** Function to insert a groups of element
	 * 
	 * @param f			Number of rows where the dron is
	 * @param c			Number of columns where the dron is
	 * @param value		Array[8] with the values, clockwise direction,
	 * 					beginning in the north
	 * @return boolean	Return if there was an error,
	 * 					false when the dron is out of range
	 */
	public boolean set(int f, int c, ArrayList<state> value){
		
		if (f<fil && c<col){
			this.set(f-1, c  , value.get(0));
			this.set(f-1, c+1, value.get(1));
			this.set(f  , c+1, value.get(2));
			this.set(f+1, c+1, value.get(3));
			this.set(f+1, c  , value.get(4));
			this.set(f+1, c-1, value.get(5));
			this.set(f  , c-1, value.get(6));
			this.set(f-1, c-1, value.get(7));
			return true;
		}
		else{
			return false;
		}
	}

	/** Function to get the value (UNKNOWN, OBSTACLE, CROSSED, UNCROSSED, OUTRANGE)
	 * 
	 * @param f			Number of rows where we want to get the first value
	 * @param c			Number of columns where we want to get the first value
	 * @return state	Return the wanted state
	 */
	public state getState (int f, int c){
		if (f<fil && c<col && f>=0 && c>=0){
			return mind.get(f).get(c);
		}
		else{
			return state.OUTOFRANGE;
		}

	}
	public int getTam() {
		return tam;
	}
	
	public void setTam(int aux) {
		if (aux > tam)
			tam=aux;
	}

	/**Function to show the matrix
	 * 
	 */
	public void show(){
		for (int i=0; i<fil ; i++){
			for (int j=0; j<col ; j++){
				switch ( mind.get(i).get(j) ){
				
					case UNKNOWN: 	System.out.print(0+" ");break;
					case OBSTACLE:	System.out.print(1+" ");break;
					case CROSSED:	System.out.print(2+" ");break;
					case UNCROSSED:	System.out.print(3+" ");break;
					case TARGET:	System.out.print(4+" ");break;
					case OUTOFRANGE:System.out.print(5+" ");break;
				}
				
				//System.out.print( mind.get(i).get(j)+" " );
			}
			System.out.println("");
		}
		System.out.println("");
	}
	
	/**Function which calculate dron's movement
	 * 
	 * @param movements			
	 * 
	 */
	public void think(ArrayList<move> movements) {
    	ArrayList<move> aux = new ArrayList<move>();
    	
    	int size = movements.size();
    	for ( int i=0; i< size ; i++ ){
	    	switch(movements.get(i)){
	    	case NORTH: if (getState(posX-1, posY).equals(state.TARGET)){
	    					aux.add(move.NORTH);
	    				}
	    				break;
	    	case EAST:	if (getState(posX, posY+1).equals(state.TARGET)){
							aux.add(move.EAST);
						}
						break;
	    	case SOUTH:	if (getState(posX+1, posY).equals(state.TARGET)){
							aux.add(move.SOUTH);
						}
						break;
	    	case WEST:	if (getState(posX, posY-1).equals(state.TARGET)){
							aux.add(move.WEST);
						}
	    				break;
	    	}
    	}
    	
    	for ( int i=0; i< size ; i++ ){
	    	switch(movements.get(i)){
	    	case NORTH: if (getState(posX-1, posY).equals(state.UNCROSSED)){
	    					aux.add(move.NORTH);
	    				}
	    				break;
	    	case EAST:	if (getState(posX, posY+1).equals(state.UNCROSSED)){
							aux.add(move.EAST);
						}
						break;
	    	case SOUTH:	if (getState(posX+1, posY).equals(state.UNCROSSED)){
							aux.add(move.SOUTH);
						}
						break;
	    	case WEST:	if (getState(posX, posY-1).equals(state.UNCROSSED)){
							aux.add(move.WEST);
						}
	    				break;
	    	}
    	}
    	
    	if (aux.isEmpty() == true){
    		for ( int i=0; i< size ; i++ ){
    	    	switch(movements.get(i)){
    	    	case NORTH: if (getState(posX-1, posY).equals(state.CROSSED)){
    	    					aux.add(move.NORTH);
    	    				}
    	    				break;
    	    	case EAST:	if (getState(posX, posY+1).equals(state.CROSSED)){
    							aux.add(move.EAST);
    						}
    						break;
    	    	case SOUTH:	if (getState(posX+1, posY).equals(state.CROSSED)){
    							aux.add(move.SOUTH);
    						}
    						break;
    	    	case WEST:	if (getState(posX, posY-1).equals(state.CROSSED)){
    							aux.add(move.WEST);
    						}
    	    				break;
    	    	}
        	}
    	}
    	
		movements.clear();
		movements.addAll(aux);
		
	}

	/**Function which choose the possible movements
	 * 
	 * @param movements	
	 * @param choices		
	 * 
	 */
	public void possibleMovements(ArrayList<move> movements, ArrayList<state> choices) {
		

    	if (choices.get(0).equals(state.CROSSED) || choices.get(0).equals(state.UNCROSSED)
    			|| choices.get(0).equals(state.TARGET)){
    		movements.add(move.NORTH);
    	}
    	if (choices.get(2).equals(state.CROSSED) || choices.get(2).equals(state.UNCROSSED)
    			|| choices.get(2).equals(state.TARGET)){
    		movements.add(move.EAST);
    	}
    	if (choices.get(4).equals(state.CROSSED) || choices.get(4).equals(state.UNCROSSED)
    			|| choices.get(4).equals(state.TARGET)){
    		movements.add(move.SOUTH);
    	}
    	if (choices.get(6).equals(state.CROSSED) || choices.get(6).equals(state.UNCROSSED)
    			|| choices.get(6).equals(state.TARGET)){
    		movements.add(move.WEST);
    	}

    	//System.out.println("movements dentro de possibleMovements = "+movements);
		
	}

	/**Function which sort the possible movements
	 * 
	 * @param movements	
	 * @param choices		
	 * 
	 */
	public void sortMovements(double angle, ArrayList<move> movements) {
		
    	ArrayList<move> aux = new ArrayList<move>();
    	
    	System.out.println("Angle en sortMovements = "+angle);
    	
		areThereObstacles();
		
		if ( obstacles == false ){
			System.out.println("NO OBSTACLES");
			if (angle >= 315 || angle <= 44){
				//System.out.println("Mayor o igual de 315 o menor o igual de 45");
				if (movements.contains(move.EAST)){
					aux.add(move.EAST);
				}
				if (movements.contains(move.SOUTH)){
					aux.add(move.SOUTH);
				}
				if (movements.contains(move.NORTH)){
					aux.add(move.NORTH);
				}
				if (movements.contains(move.WEST)){
					aux.add(move.WEST);
				}
	
			}
			else{
				if ( angle > 44 && angle <= 135 ){
					//System.out.println("Mayor de 45 y menor o igual de 135");
					if (movements.contains(move.SOUTH)){
						aux.add(move.SOUTH);
					}
					if (movements.contains(move.EAST)){
						aux.add(move.EAST);
					}
					if (movements.contains(move.WEST)){
						aux.add(move.WEST);
					}
					if (movements.contains(move.NORTH)){
						aux.add(move.NORTH);
					}
				}
				else{
					if ( angle > 135 && angle <= 225 ){
						//System.out.println("Mayor de 135 y menor o igual a 225");
						if (movements.contains(move.WEST)){
							aux.add(move.WEST);
						}
						if (movements.contains(move.SOUTH)){
							aux.add(move.SOUTH);
						}
						if (movements.contains(move.NORTH)){
							aux.add(move.NORTH);
						}
						if (movements.contains(move.EAST)){
							aux.add(move.EAST);
						}
					}
					else{
						//System.out.println("Restoo...");
						if (movements.contains(move.NORTH)){
							aux.add(move.NORTH);
						}
						if (movements.contains(move.EAST)){
							aux.add(move.EAST);
						}
						if (movements.contains(move.WEST)){
							aux.add(move.WEST);
						}
						if (movements.contains(move.SOUTH)){
							aux.add(move.SOUTH);
						}
					}
				}
			}
			//System.out.println("ArrayList aux = "+aux);
			movements.clear();
			//movements = new ArrayList<move>();
			movements.addAll(aux);
			//System.out.println("ArrayList movements = "+movements);
		}
		
		//Si hay obstáculos tendrá que seguir un procedimiento diferente
		// tendrá que seguir unas mismas direcciones hasta que evite el
		// obstáculo
		else{
			System.out.println("OBSTACLES!");
			System.out.println("LimitedMoves tiene: "+limitedMoves);
			if ( limitedMoves.isEmpty() == false ){
				if (limitedMoves.size() == 1){
					//System.out.println(" limitedMoves.size() == 1 ");
					switch ( limitedMoves.get(0) ){
					case NORTH:	//System.out.println("NORTH");
					case SOUTH: //System.out.println("SOUTH");
								if ( angle <= 90 || angle >= 270 ){
									if (movements.contains(move.EAST)){
										//System.out.println("movements contains EAST");
										limitedMoves.add(move.EAST);
									}
									/*else{
										if (movements.contains(move.WEST)){
											//System.out.println("movements contains WEST");
											limitedMoves.add(move.WEST);
										}
									}*/
									
								}
								else{
									if (movements.contains(move.WEST)){
										//System.out.println("movements contains WEST");
										limitedMoves.add(move.WEST);
									}
									/*else{
										if (movements.contains(move.EAST)){
											//System.out.println("movements don't contains WEST");
											limitedMoves.add(move.EAST);
										}
									}*/
								}
						break;
					case WEST:	//System.out.println("WEST");
					case EAST: 	//System.out.println("EAST");
								if ( angle <= 180 ){
									if (movements.contains(move.SOUTH)){
										limitedMoves.add(move.SOUTH);
									}
									/*else{
										if (movements.contains(move.NORTH)){
											limitedMoves.add(move.NORTH);
										}
									}*/
								}
								else{
									if (movements.contains(move.NORTH)){
										limitedMoves.add(move.NORTH);
									}
									/*else{
										if (movements.contains(move.SOUTH)){
											limitedMoves.add(move.SOUTH);
										}
									}*/
								}
						break;
					}
					aux.clear();
					if (angle >= 315 || angle <= 44){
						//System.out.println("Mayor o igual de 315 o menor o igual de 45");
						if (limitedMoves.contains(move.EAST)){
							aux.add(move.EAST);
						}
						if (limitedMoves.contains(move.SOUTH)){
							aux.add(move.SOUTH);
						}
						if (limitedMoves.contains(move.NORTH)){
							aux.add(move.NORTH);
						}
						if (limitedMoves.contains(move.WEST)){
							aux.add(move.WEST);
						}
			
					}
					else{
						if ( angle > 44 && angle <= 135 ){
							//System.out.println("Mayor de 45 y menor o igual de 135");
							if (limitedMoves.contains(move.SOUTH)){
								aux.add(move.SOUTH);
							}
							if (limitedMoves.contains(move.EAST)){
								aux.add(move.EAST);
							}
							if (limitedMoves.contains(move.WEST)){
								aux.add(move.WEST);
							}
							if (limitedMoves.contains(move.NORTH)){
								aux.add(move.NORTH);
							}
						}
						else{
							if ( angle > 135 && angle <= 225 ){
								//System.out.println("Mayor de 135 y menor o igual a 225");
								if (limitedMoves.contains(move.WEST)){
									aux.add(move.WEST);
								}
								if (limitedMoves.contains(move.SOUTH)){
									aux.add(move.SOUTH);
								}
								if (limitedMoves.contains(move.NORTH)){
									aux.add(move.NORTH);
								}
								if (limitedMoves.contains(move.EAST)){
									aux.add(move.EAST);
								}
							}
							else{
								//System.out.println("Restoo...");
								if (limitedMoves.contains(move.NORTH)){
									aux.add(move.NORTH);
								}
								if (limitedMoves.contains(move.EAST)){
									aux.add(move.EAST);
								}
								if (limitedMoves.contains(move.WEST)){
									aux.add(move.WEST);
								}
								if (limitedMoves.contains(move.SOUTH)){
									aux.add(move.SOUTH);
								}
							}
						}
					}
					limitedMoves.clear();
					limitedMoves.addAll(aux);
				}
				else if (limitedMoves.size() == 2){
					
					
					
				}
				//else if (limitedMoves.size() == 2){
					//algo como:
				//	limitedMejorable(limitedMoves, movements, angle);
				//}
				if (limitedMoves.size() == 1){
					if ( movements.contains(limitedMoves.get(0)) ){
						movements.clear();
						movements.addAll(limitedMoves);
					}
				}
				else{
					if ( movements.contains(limitedMoves.get(0)) || movements.contains(limitedMoves.get(1)) ){
						movements.clear();
						movements.addAll(limitedMoves);
					}
				}
				

			}
			else{
				if (angle >= 315 || angle <= 45){
					//System.out.println("Mayor o igual de 315 o menor o igual de 45");
					if (movements.contains(move.EAST)){
						aux.add(move.EAST);
					}
					if (movements.contains(move.SOUTH)){
						aux.add(move.SOUTH);
					}
					if (movements.contains(move.NORTH)){
						aux.add(move.NORTH);
					}
					if (movements.contains(move.WEST)){
						aux.add(move.WEST);
					}
		
				}
				else{
					if ( angle > 45 && angle <= 135 ){
						//System.out.println("Mayor de 45 y menor o igual de 135");
						if (movements.contains(move.SOUTH)){
							aux.add(move.SOUTH);
						}
						if (movements.contains(move.EAST)){
							aux.add(move.EAST);
						}
						if (movements.contains(move.WEST)){
							aux.add(move.WEST);
						}
						if (movements.contains(move.NORTH)){
							aux.add(move.NORTH);
						}
					}
					else{
						if ( angle > 135 && angle <= 225 ){
							//System.out.println("Mayor de 135 y menor o igual a 225");
							if (movements.contains(move.WEST)){
								aux.add(move.WEST);
							}
							if (movements.contains(move.SOUTH)){
								aux.add(move.SOUTH);
							}
							if (movements.contains(move.NORTH)){
								aux.add(move.NORTH);
							}
							if (movements.contains(move.EAST)){
								aux.add(move.EAST);
							}
						}
						else{
							//System.out.println("Restoo...");
							if (movements.contains(move.NORTH)){
								aux.add(move.NORTH);
							}
							if (movements.contains(move.EAST)){
								aux.add(move.EAST);
							}
							if (movements.contains(move.WEST)){
								aux.add(move.WEST);
							}
							if (movements.contains(move.SOUTH)){
								aux.add(move.SOUTH);
							}
						}
					}
				}

				//System.out.println("Aux ==== "+aux);
				limitedMoves.add(aux.get(0));
				switch (aux.get(0)){
				case NORTH:	//System.out.println("NORTH");
				case SOUTH: //System.out.println("SOUTH");
							if (angle <= 90 || angle >= 270){
								if (movements.contains(move.EAST)){
									//System.out.println("movements contains EAST");
									limitedMoves.add(move.EAST);
								}
							}
							else{
								if (movements.contains(move.WEST)){
									//System.out.println("movements contains WEST");
									limitedMoves.add(move.WEST);
								}
							}
					break;
				case WEST:	//System.out.println("WEST");
				case EAST: 	//System.out.println("EAST");
							if ( angle <= 180){
								if (movements.contains(move.SOUTH)){
									limitedMoves.add(move.SOUTH);
								}
							}
							else{
								if (movements.contains(move.NORTH)){
									limitedMoves.add(move.NORTH);
								}

							}
					break;
				}
				movements.clear();
				movements.addAll(limitedMoves);
			}

		}

	}
	

	public int getPosX() {
		return posX;
	}

	public void setPosX(int posX) {
		this.posX = posX;
		set(this.posX, this.posY, state.CROSSED);
	}

	public int getPosY() {
		return posY;
	}

	public void setPosY(int posY) {
		this.posY = posY;
		set(this.posX, this.posY, state.CROSSED);
	}

	public void showPos(int posX2, int posY2) {
		
		System.out.print  ( getState(posX2-1, posY2-1)+" " );
		System.out.print  ( getState(posX2-1, posY2  )+" " );
		System.out.println( getState(posX2-1, posY2+1)+" " );
		
		System.out.print  ( getState(posX2  , posY2-1)+" " );
		System.out.print  ( getState(posX2  , posY2  )+" " );
		System.out.println( getState(posX2  , posY2+1)+" " );
		
		System.out.print  ( getState(posX2+1, posY2-1)+" " );
		System.out.print  ( getState(posX2+1, posY2  )+" " );
		System.out.println( getState(posX2+1, posY2+1)+" " );
		
	}
	
	public void areThereObstacles (){
		boolean entro=true;
		
		if (obstacles == false){
			if 	( getState(posX-1,posY  ).equals(state.OBSTACLE) ){
				obstacles=true; entro=false;
			}
			/*if	( getState(posX-1,posY+1).equals(state.OBSTACLE) ){
				obstacles=true; entro=false;
			}*/
			if	( getState(posX  ,posY+1).equals(state.OBSTACLE) ){
				obstacles=true; entro=false;
			}
			/*if	( getState(posX+1,posY+1).equals(state.OBSTACLE) ){
				obstacles=true; entro=false;
			}*/
			if	( getState(posX+1,posY  ).equals(state.OBSTACLE) ){
				obstacles=true; entro=false;
			}
			/*if	( getState(posX+1,posY-1).equals(state.OBSTACLE) ){
				obstacles=true; entro=false;
			}*/
			if	( getState(posX  ,posY-1).equals(state.OBSTACLE) ){
				obstacles=true; entro=false;
			}
			/*if	( getState(posX-1,posY-1).equals(state.OBSTACLE) ){
				obstacles=true; entro=false;
			}*/
		}
		else{
			if 	( getState(posX-1,posY  ).equals(state.OBSTACLE) ){
				obstacles=true; entro=false;
			}
			if	( getState(posX-1,posY+1).equals(state.OBSTACLE) ){
				obstacles=true; entro=false;
			}
			if	( getState(posX  ,posY+1).equals(state.OBSTACLE) ){
				obstacles=true; entro=false;
			}
			if	( getState(posX+1,posY+1).equals(state.OBSTACLE) ){
				obstacles=true; entro=false;
			}
			if	( getState(posX+1,posY  ).equals(state.OBSTACLE) ){
				obstacles=true; entro=false;
			}
			if	( getState(posX+1,posY-1).equals(state.OBSTACLE) ){
				obstacles=true; entro=false;
			}
			if	( getState(posX  ,posY-1).equals(state.OBSTACLE) ){
				obstacles=true; entro=false;
			}
			if	( getState(posX-1,posY-1).equals(state.OBSTACLE) ){
				obstacles=true; entro=false;
			}
		}
		
		
		if (entro){
			obstacles=false;
			if (limitedMoves.isEmpty() == false){
				//System.out.println("limitedMoves.clear()");
				limitedMoves.clear();
			}
			
		}
		
	}
	
	public boolean isDeadEnd(int xAnt, int yAnt, int xCros, int yCros, move lastMove, int cont){
		
		//System.out.println("cont = "+cont);
		if ( xAnt == xCros && yAnt == yCros ){
			//System.out.println("xAnt == xCros && yAnt == yCros");
			return true;
		}
		else{
			//System.out.println(getState(xCros-1,yCros ));
			switch (lastMove){
			case NORTH:	if 	( getState(xCros-1,yCros  ).equals(state.CROSSED) ){
							//System.out.println("NORTE hay CROSSED");
							if (isDeadEnd (xAnt, yAnt, xCros-1, yCros, move.NORTH, cont++) ){
								tam++;
								return true;
							}
						}
			
						if	( getState(xCros  ,yCros+1).equals(state.CROSSED) ){
							//System.out.println("EAST hay CROSSED");
							if (isDeadEnd (xAnt, yAnt, xCros, yCros+1,move.EAST, cont++) ){
								tam++;
								return true;
							}
						}
			
						if	( getState(xCros  ,yCros-1).equals(state.CROSSED) ){
							//System.out.println("WEST hay CROSSED");
							if (isDeadEnd (xAnt, yAnt, xCros, yCros-1,move.WEST, cont++) ){
								tam++;
								return true;
							}
						}
						break;
			case SOUTH:	if 	( getState(xCros+1,yCros  ).equals(state.CROSSED) ){
							//System.out.println("NORTE hay CROSSED");
							if (isDeadEnd (xAnt, yAnt, xCros+1, yCros, move.SOUTH, cont++) ){
								tam++;
								return true;
							}
						}
			
						if	( getState(xCros  ,yCros+1).equals(state.CROSSED) ){
							//System.out.println("EAST hay CROSSED");
							if (isDeadEnd (xAnt, yAnt, xCros, yCros+1,move.EAST, cont++) ){
								tam++;
								return true;
							}
						}
			
						if	( getState(xCros  ,yCros-1).equals(state.CROSSED) ){
							//System.out.println("WEST hay CROSSED");
							if (isDeadEnd (xAnt, yAnt, xCros  , yCros-1,move.WEST, cont++) ){
								tam++;
								return true;
							}
						}
						break;
			case EAST:	if 	( getState(xCros-1,yCros  ).equals(state.CROSSED) ){
							//System.out.println("NORTE hay CROSSED");
							if (isDeadEnd (xAnt, yAnt, xCros-1, yCros, move.NORTH, cont++) ){
								tam++;
								return true;
							}
						}
			
						if	( getState(xCros  ,yCros+1).equals(state.CROSSED) ){
							//System.out.println("EAST hay CROSSED");
							if (isDeadEnd (xAnt, yAnt, xCros  , yCros+1,move.EAST, cont++) ){
								tam++;
								return true;
							}
						}
			
						if	( getState(xCros+1,yCros  ).equals(state.CROSSED) ){
							//System.out.println("WEST hay CROSSED");
							if (isDeadEnd (xAnt, yAnt, xCros+1, yCros  ,move.SOUTH, cont++) ){
								tam++;
								return true;
							}
						}
						break;
			case WEST:	if 	( getState(xCros-1,yCros  ).equals(state.CROSSED) ){
							//System.out.println("NORTE hay CROSSED");
							if (isDeadEnd (xAnt, yAnt, xCros-1, yCros, move.NORTH, cont++) ){
								tam++;
								return true;
							}
						}
			
						if	( getState(xCros+1,yCros  ).equals(state.CROSSED) ){
							//System.out.println("EAST hay CROSSED");
							if (isDeadEnd (xAnt, yAnt, xCros+1, yCros,move.SOUTH, cont++) ){
								tam++;
								return true;
							}
						}
			
						if	( getState(xCros  ,yCros-1).equals(state.CROSSED) ){
							//System.out.println("WEST hay CROSSED");
							if (isDeadEnd (xAnt, yAnt, xCros, yCros-1,move.WEST, cont++) ){
								tam++;
								return true;
							}
						}
						break;
			}
		}

		return false;
	}
	
	public ArrayList<move> areThereCrossedPlaces( ){
		
		ArrayList<move> aux= new ArrayList<move>();
		
		if 	( getState(posX-1,posY  ).equals(state.CROSSED) ){
			aux.add(move.NORTH);
		}

		if	( getState(posX  ,posY+1).equals(state.CROSSED) ){
			aux.add(move.EAST);
		}

		if	( getState(posX+1,posY  ).equals(state.CROSSED) ){
			aux.add(move.SOUTH);
		}

		if	( getState(posX  ,posY-1).equals(state.CROSSED) ){
			aux.add(move.WEST);
		}
		
		return aux;
	}

	public void block(int pos1, int pos2) {
		
		mind.get(pos1).set( pos2 , state.UNCROSSED);
		
	}

	public boolean isDeadEnd2(int ant1, int ant2, int crosX, int crosY,
			move cross, ArrayList<Pair> way) {
		
		int tam= way.size();
		for (int i = 0; i<tam; ++i){
			
		}
		
		
		return false;
	}

}
